package com.scan.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import utils.WeixinTools;
import com.scan.config.WxProperties;
import com.scan.dao.model.User;
import com.scan.dao.model.VoteSubject;
import com.scan.service.RedisService;
import com.scan.service.UserService;
import com.scan.service.VoteSubjectService;

/**
 * Created by tancw on 2017/2/20.
 */
@Controller
public class HomeController {

    @Autowired
    private UserService userService;
    @Autowired
    private VoteSubjectService voteSubjectService;
    @Autowired
    private WxProperties wxProperties;
    @Autowired
    private RedisService redisService;

    @RequestMapping("/")
    public String index(Model model, HttpServletRequest request) {
        VoteSubject voteSubject = voteSubjectService.getSubjectById(1);
        model.addAttribute("vote",voteSubject);
        String url = request.getRequestURI().toString();
        model.addAttribute("wxConfig", WeixinTools.getWxConfig(wxProperties.getAppID(),url));
        return "index";
    }

    @RequestMapping("list")
    @ResponseBody
    public List<User> list(){
        return userService.list();
    }


}
